#ifndef PROXY_ENCRY_ENCRYBASE_H_
#define PROXY_ENCRY_ENCRYBASE_H_

#include "proxy/base/proxybase.h"

namespace proxy{

  const char ENCRY_END_CHAR_SET[] = { '\r', '\n', '\r', '\n' };
  const int ENCRY_END_SIZE = 4;
  const char HTTP_KEY = '#';
  const int RANDOM_SIZE = 16;

  const char BING_ENCRY_REPLY[] = "HTTP/1.1 200 OK\r\n"
    "Cache-Control: public, max-age=1209600\r\n"
    "Content-Type: application/x-epi\r\n"
    "Server: Microsoft-IIS/8.5\r\n"
    "\r\n";

  const int MAX_ENCRY_HEADER_SIZE = 512;
  struct EncryRequest{
    char encry_header[MAX_ENCRY_HEADER_SIZE];
    int  encry_header_size;
    int  encry_repeat_size;
  };


  const int ENCRY_REQUEST_SET_SIZE = 2;
  const EncryRequest ENCRY_REQUEST_SET[ENCRY_REQUEST_SET_SIZE] = {
    {
      "POST /fd/ls/lsp.aspx HTTP/1.1\r\n"
      "Accept: */*\r\n"
      "Host: www.bing.com\r\n"
      "Connection: Keep-Alive\r\n"
      "Content-Type: application/x-epi\r\n"
      "Cookie: SRCHUID=V=2&RC=#;\r\n"
      "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko\r\n"
      "\r\n",
      233,
      16,
    },
    {
      "GET /fdrc/ls/lsp.aspx HTTP/1.1\r\n"
      "Accept: */*\r\n"
      "Host: www.bing.com\r\n"
      "Connection: Keep-Alive\r\n"
      "Content-Type: application/x-epi\r\n"
      "Cookie: MUIDB=2E7EBF713CEB6FB13D91B86F3DF86FEF;&RC=#;\r\n"
      "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko\r\n"
      "\r\n",
      262,
      16,
    }
  };

  struct EncryReply{
    char encry_reply[512];
    int encry_reply_size;
  };

  const int ENCRY_REPLY_SIZE = 2;
  const EncryReply ENCRY_REPLY[ENCRY_REPLY_SIZE] = {
    {
      "HTTP/1.1 200 OK\r\n"
      "Cache-Control: public, max-age=1209600\r\n"
      "Content-Type: application/x-epi\r\n"
      "Server: Microsoft-IIS/8.5\r\n"
      "\r\n",
      119
    },
    {
      "HTTP/1.1 404 Bad Request\r\n"
      "Cache-Control: public, max-age=1209600\r\n"
      "Content-Type: application/x-epi\r\n"
      "Server: Microsoft-IIS/8.5\r\n"
      "\r\n",
      128
    }
  };

  void EncryData(char* data, int size, unsigned key);
  void DecodeData(char* data, int size, unsigned key);
  std::string RandomString(int size);
  char AddRandomChar(std::string &str, int size);
  int InitEncryKey();
}

#endif // PROXY_ENCRY_ENCRYBASE_H_